package com.wang.friend.controller;

import com.wang.friend.aspect.CheckUserStatus;
import com.wang.common.core.constants.HttpConstants;
import com.wang.common.core.controller.BaseController;
import com.wang.common.core.domain.R;
import com.wang.common.core.domain.TableDataInfo;
import com.wang.friend.domain.exam.dto.ExamDTO;
import com.wang.friend.domain.exam.dto.ExamQueryDTO;
import com.wang.friend.service.IUserExamService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "用户竞赛功能接口")
@RestController
@RequestMapping("/user/exam")
public class UserExamController {

    @Autowired
    private IUserExamService userExamService;

    @CheckUserStatus //加上该注解,如果用户被封禁,则限制用户报名竞赛
    @Operation(summary = "用户竞赛报名")
    @PostMapping("/enter")
    public R<Void> enter(@RequestHeader(HttpConstants.AUTHENTICATION) String token, @RequestBody ExamDTO examDTO){
        return BaseController.toR(userExamService.enter(token, examDTO.getExamId()));
    }

    @Operation(summary = "查询用户已经报名的竞赛列表")
    @GetMapping("/list")
    public TableDataInfo list(ExamQueryDTO examQueryDTO){
        return userExamService.list(examQueryDTO);
    }
}


